package org.oos.lists;

import java.util.AbstractList;
import java.util.List;

import org.oos.OOS4Java;
import org.oos.atom.entries.CheckinEntry;
import org.oos.model.Checkin;
import org.oos.util.Cache;

public class CheckinList extends AbstractList<Checkin> {

	private OOS4Java oos4Java;
	private List<CheckinEntry> list;
	private Cache<CheckinEntry, Checkin> cache = new Cache<CheckinEntry, Checkin>();

	public CheckinList(OOS4Java oos4Java, List<CheckinEntry> list) {
		this.oos4Java = oos4Java;
		this.list = list;
	}

	@Override
	public Checkin get(int location) {
		CheckinEntry entry = list.get(location);
		Checkin result;
		if (cache.containsKey(entry)) {
			result = cache.get(entry);
		} else {
			result = new Checkin(oos4Java, list.get(location));
			cache.put(entry, result);
		}
		return result;
	}

	@Override
	public int size() {
		return list.size();
	}
}
